// Copyright (C) 2025 Focus Media Holding Ltd. All Rights Reserved.

package cn.pacerx.running.wx.web;

import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.pacerx.running.core.util.ResponseUtil;
import cn.pacerx.running.wx.service.EventService;
import cn.pacerx.running.wx.vo.EventDetailVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * EventController
 *
 * @author zhanglingwei@focusmedia.cn
 * @since 2025-06-06
 */
@RestController
@RequestMapping("/wx/event")
@Validated
@RequiredArgsConstructor
public class EventController {
    private final EventService eventService;

    /**
     * 事件列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "事件列表")
    public Object list() {
        return ResponseUtil.okList(eventService.getList());
    }

    /**
     * 事件详情
     *
     * @param id     事件ID
     * @return 事件详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "事件明细")
    public Object detail(@RequestParam("id") Long id) {
        return eventService.getDetail(id);
    }

    /**
     * 添加或更新事件
     *
     * @param detailVo 事件
     * @return 添加或更新操作结果
     */
    @PostMapping("save")
    @ApiOperation(value = "新增or保存事件")
    public Object save(@RequestBody @Valid EventDetailVo detailVo) {
        return eventService.save(detailVo);
    }

    /**
     * 删除事件
     *
     * @param id 用户事件id
     * @return 删除操作结果
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除事件")
    public Object delete(@PathVariable("id") Long id) {
        return eventService.delete(id);
    }
}
